package mya.mes.mdc.logic.plc;

import mya.mes.mdc.share.plc.TagPrefix;

public class PlcTagTypeIdBuilder {

    private static final long AI = 1_0000_00L;
    private static final long DI = 2_0000_00L;
    private static final long ST = 3_0000_00L;


    public static long buildId(String prefix, Integer tagIndex, Integer bitIndex) {

        if (bitIndex == null) {
            bitIndex = 0;
        }

        if (TagPrefix.AI.equals(prefix)) {
            return AI + tagIndex * 100 + bitIndex;
        }

        if (TagPrefix.DI.equals(prefix)) {
            return DI + tagIndex * 100 + bitIndex;
        }

        if (TagPrefix.ST.equals(prefix)) {
            return ST + tagIndex * 100 + bitIndex;
        }

        throw new RuntimeException("Unknown mdc tag prefix: " + prefix);
    }
}
